<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>proxy代理</title>
</head>
<body>
  
</body>
<script>
  let obj = {
    name: 'zhangli',
    age: 31
  }
  let proxyObj = new Proxy(obj, {
    get (obj, prop) {
      console.log(`获取了${prop}属性`)
      return obj[prop]
    },
    set (obj, prop, val) {
      console.log(`设置了${prop}属性的值为${val}`)
      obj[prop] = val
    },
    deleteProperty(obj, prop) {
      console.log(`删除了${prop}属性的值`)
      delete obj[prop]
    }
  })
  console.log(proxyObj.name)
  proxyObj.name = 'chentain'
  console.log(proxyObj.name)
  // Reflect对象，提供了一种更加标准，友好的方式来对对象对象操作，以函数的方式实现了传统了object命令式操作
  Reflect.set(obj, 'name', 'haha')
  console.log(Reflect.get(obj,'name'))
  
</script>
</html>